<template>
  <div>
    <el-container>
      <el-header>
        <el-menu 
          :default-active="activeIndex2"
          class="el-menu-demo"
          mode="horizontal"
          @select="topMenuSelect"
          background-color="#545c64"
          text-color="#fff"
          text-align="right"
          active-text-color="#ffd04b"
        >
          <el-submenu index="100" >
            <template slot="title">{{loginUser.user_full_name}}</template>
            <el-menu-item index="100-1">个人中心</el-menu-item>
            <el-menu-item index="100-2">退出登录</el-menu-item>
            <el-menu-item index="100-2">消息中心</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-header>
      <el-container>
        <el-aside>
          <h5>{{ system_title }}</h5>
          <div class="navMenu">
            <leftMenu
              :default_active_prop="defualt_open_menu_key"
              :menuData="menu_data"
            ></leftMenu>
          </div>
        </el-aside>
        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<script>
import leftMenu from "@/components/layout/LeftMenu.vue"; //引用递归菜单组件
export default {
  name: "Index",
  data() {
    return {
      activeIndex2: "2",
      system_title: "",
      menu_data: [],
      defualt_open_menu_key: "",
      loginUser:{ }
    };
  },
  created() {
    this.Ini();
  },
  methods: {
    Ini() {
      this.$myaxios
        .get("SystemManager/WebSystemMenuManager/GetUserWebSystemMenuPo")
        .then((r) => {
          if (r.data && r.data.length > 0) {
            var one = r.data[0];
            this.system_title = one.wm_name;
            this.menu_data = one.sonWebSystemMenuViewList;
            this.defualt_open_menu_key =
              one.sonWebSystemMenuViewList[0].wm_code;
              this.loginUser=this.$cookieTools.getLoginUser();
          }
        });
    },
    LoginOut(){
        this.$myaxios
        .get("SystemManager/AdminUserManager/LoginOut")
        .then((r) => {
          if (r.data ) {
            this.$cookieTools.removeLoginUser();
             this.$router.push("/");
          }
          else
          {
            this.$message('操作失败,'+r.mess)
          }
        });
    },
    topMenuSelect(key, keyPath) {
      switch(key)
      {
        case "100-2":
        this.LoginOut();
        break;
        
      }
      console.log(key, keyPath);
    },
  },
  components: {
    leftMenu,
  },
};
</script>
